/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import com.sun.lwuit.Form;
import com.sun.lwuit.TextField;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.Command;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;

/**
 *
 * @author Kvest
 */
public class SumFilterForm extends Form implements ActionListener
{
    public static final int OK_ID = 1;
    public static final int BACK_ID = 2;
    
    private Command ok;
    private Command back;
    private FormAction listener;

    private TextField sumFilter;

    public SumFilterForm(FormAction listener)
    {
        super("Фильтр");

        this.listener = listener;

        init();
    }

    private void init()
    {
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));

        addCommandListener(this);

        back= new Command("Назад", BACK_ID);
        addCommand(back);

        ok = new Command("Ok", OK_ID);
        addCommand(ok);

        addComponent(new Label("Минимальная сумма: "));

        sumFilter = new TextField();
        sumFilter.setConstraint(com.sun.lwuit.TextField.NUMERIC);
        sumFilter.setInputMode("123");
        sumFilter.setSelectCommandText("");
        addComponent(sumFilter);
    }

    public void show(String sumValue)
    {
        sumFilter.setText(sumValue);

        super.show();
    }

    public void actionPerformed(ActionEvent evt)
    {
        if (listener != null)
        {
            listener.commandAction(evt.getCommand().getId());
        }
    }

    public String getSum()
    {
        return sumFilter.getText();
    }
}
